package com.yc.mypredicatefactory;//package com.yc.mypredicatefactory;
//
//import jakarta.validation.constraints.NotNull;
//import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory;
//import org.springframework.stereotype.Component;
//import org.springframework.web.server.ServerWebExchange;
//
//import java.time.LocalTime;
//import java.util.Arrays;
//import java.util.List;
//import java.util.function.Predicate;
//
///**
// * @program: cloud147
// * @description:
// * @author: zy
// * @create: 2025-07-16 15:46
// */
//@Component
//public class TimeLimitBetweenRoutePredicateFactory extends AbstractRoutePredicateFactory<TimeLimitBetweenRoutePredicateFactory.CustomTimeBetweenConfig> {
//    public static final String DATETIME1_KEY = "datetime1";
//
//    /**
//     * DateTime 2 key.
//     */
//    public static final String DATETIME2_KEY = "datetime2";
//
//    public TimeLimitBetweenRoutePredicateFactory() {
//        super(TimeLimitBetweenRoutePredicateFactory.CustomTimeBetweenConfig.class);
//    }
//
//    @Override
//    public List<String> shortcutFieldOrder() {
//        return Arrays.asList(DATETIME1_KEY, DATETIME2_KEY);
//    }
//
//    @Override
//    public Predicate<ServerWebExchange> apply(CustomTimeBetweenConfig config) {
//        //获取参数值
//        LocalTime startTime = config.getDatetime1();
//        LocalTime endTime = config.getDatetime2();
//        //创建谓词对象
//        return new Predicate<ServerWebExchange>() {
//            @Override
//            public boolean test(ServerWebExchange serverWebExchange) {
//                LocalTime now = LocalTime.now();
//                //判断当前时间是否在在配置的时间范围类
//                return now.isAfter(startTime) && now.isBefore(endTime);
//            }
//        };
//    }
//
//
//    public static class CustomTimeBetweenConfig {
//
//        @NotNull
//        private LocalTime datetime1;
//
//        @NotNull
//        private LocalTime datetime2;
//
//        public LocalTime getDatetime1() {
//            return datetime1;
//        }
//
//        public void setDatetime1(LocalTime datetime1) {
//            this.datetime1 = datetime1;
//        }
//
//        public LocalTime getDatetime2() {
//            return datetime2;
//        }
//
//        public void setDatetime2(LocalTime datetime2) {
//            this.datetime2 = datetime2;
//        }
//    }
//}
